package Game;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;

import javax.swing.Timer;
/**
 * This is the watch that count the time
 * @author wat wattanagaroon
 * @author Parinthorn Panya
 * @version 2013/05/10
 *
 */
public class Watch extends Observable {

	/** time when stopwatch was started. */
	private int time;
	private Timer timer;
	protected Watch me;
	private StopWatch stopWatch;
	/**
	 * The constructor for the watch.
	 */
	public Watch() {
		me = this;
		stopWatch = new StopWatch();
		this.time = 60;
		timer = new Timer(1000, new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				time -= 1;
				setChanged();
				notifyObservers(me);
			}
		});
		timer.start();
		stopWatch.start();
	}
	/**
	 * To make the new round of the time.
	 */
	public void timeAgain() {
		this.time = 60;
		timer.start();
		stopWatch.start();

	}
	/**
	 * This is the method for stop the time.
	 */
	public void stopTime(){
		timer.stop();
		stopWatch.stop();
	}
	/**
	 * This is the method to get the time
	 * @return the time
	 */
	public int getTime() {
		return time;
	}
	/**
	 * This is the method to get the 
	 * @return the time that elapsed
	 */
	public double getElapseTime(){
		return stopWatch.getElapsed();
	}
}
